import { ResponseCode } from "@/enum/ResponseCode";
import { getAppAnswerCount } from "@/servers/api/appStatisticController";
import { getVisitCount } from "@/servers/api/websiteStatisticController";
import { Line } from "@ant-design/charts";
import { Message } from "@arco-design/web-react";
import { useEffect, useState } from "react";
export default () => {
  const [data, setData] = useState<API.WebVisitCountVO[]>();
  const [config, setConfig] = useState({
    title: {
      title: "网站访问量趋势",
      titleFontSize: 25,
    },
    data,
    xField: "visitDate",
    yField: "visitCount",
    point: {
      shapeField: "square",
      sizeField: 4,
    },
    interaction: {
      tooltip: {
        marker: false,
      },
    },
    style: {
      lineWidth: 2,
    },
  });
  const loadData = async () => {
    let res = await getVisitCount();
    if (res.data.code === ResponseCode.SUCCESS) {
      setData(res.data.data as API.WebVisitCountVO[]);
      let temp = res.data.data?.sort((a, b) =>
        //@ts-ignore
        a.visitDate.localeCompare(b.visitDate)
      );
      setConfig({ ...config, data: temp });
    } else {
      Message.error(res.data.message as string);
    }
  };
  useEffect(() => {
    loadData();
  }, []);
  return (
    <Line
      {...config}
      containerStyle={{
        background: "white",
        borderRadius: "10px",
        height: "400px",
      }}
    />
  );
};
